package com.mediatecture.flex.component.ExportPHPP
{	
	import Controller.AreasController;
	
	import Model.Areas;
	import Model.Calculations;
	import Model.ComplexSolidComponent;
	import Model.Project;
	import Model.SolidComponent;
	import Model.TransparentComponent;
	
	import mx.collections.ArrayCollection;
	import mx.resources.IResourceManager;
	import mx.resources.ResourceManager;

	public class PhppXMLexport
	{	
		import mx.core.FlexGlobals;
		
		private var exportXML:XML =
			<PhppExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.diewerkbank.eu/ExportPhpp">
			</PhppExport>;
		
		private var VerificationXML:XML =
			<Verification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
				<Building>
					<Name></Name>
					<LocationAndClimate></LocationAndClimate>
					<PostCodeCity></PostCodeCity>
					<Country></Country>
					<Type></Type>
				</Building>
				<HomeOwnerClient>
					<Name></Name>
					<PostCodeCity></PostCodeCity>
				</HomeOwnerClient>
				<Architect>
					<Name></Name>
					<Street></Street>
					<PostCodeCity></PostCodeCity>
					<Country></Country>
				</Architect>
				<MechanicalSystem>
					<Name></Name>
					<Street></Street>
					<PostCodeCity></PostCodeCity>
					<Country></Country>
				</MechanicalSystem>
				<YearOfConstruction></YearOfConstruction>
				<NumberOfDwellingUnits></NumberOfDwellingUnits>
				<EnclosedVolumeVe></EnclosedVolumeVe>
				<InteriorTemperature></InteriorTemperature>
				<CalcElecBuildType></CalcElecBuildType>
				<InternHeatGainUtilPtrn></InternHeatGainUtilPtrn>
				<InternHeatGainType></InternHeatGainType>
				<PlannedNoOcupants></PlannedNoOcupants>
				<PlannedNoOcupantsType></PlannedNoOcupantsType>
				<VerificationMethod></VerificationMethod>
			</Verification>;
		
		private var buildingElement:XML;
		private var doorElement:XML;
		private var windowElement:XML;
		private var glazingElement:XML;
		private var frameElement:XML;
		
		private var buildingElementsTag:XML = <BuildingElements></BuildingElements>;
		
		private var thermalBridges:XML = 
			<ThermalBridges>
				<ThermalBridge>
					<Description></Description>
					<GroupNr></GroupNr>
					<Quantity></Quantity>
					<UserDeterminedLength></UserDeterminedLength>
					<Substraction></Substraction>
					<WmK></WmK>
				</ThermalBridge>
			</ThermalBridges>;
		
		private var radiation:XML = 
			<RadiationBalances>
				<RadiationBalance>
					<ExteriorAbsorptivity></ExteriorAbsorptivity>
					<ExteriorEmissivity></ExteriorEmissivity>
					<DeviationFromNorth></DeviationFromNorth>
					<Angle></Angle>
					<ReductionFactorShading></ReductionFactorShading>
				</RadiationBalance>
			</RadiationBalances>;
		
		private var threatedFloorArea:XML = 
			<ThreatedFloorArea>
				<Quantity></Quantity>
				<A/>
				<B/>
				<UserDetermined></UserDetermined>
				<UserSubtraction></UserSubtraction>
			</ThreatedFloorArea>;
		
		private var AreasXML:XML =
			<Areas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<AreaGroup12>Wall - Unheated Cellar</AreaGroup12>
			<AreaGroup12TempZone>B</AreaGroup12TempZone>
			<AreaGroup13>Slab - Unheated Cellar</AreaGroup13>
			<AreaGroup13TempZone>B</AreaGroup13TempZone>
			</Areas>;
		
		private var UValuesXML:XML =
			<UValues xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
				<Assemblies>
					<Assembly>
						<AssemblyNr></AssemblyNr>
						<AssemblyName></AssemblyName>
						<InteriorRsi></InteriorRsi>
						<ExteriorRse></ExteriorRse>
						<AreaSection>
							<AreaSection1Name></AreaSection1Name>
							<Lambda1></Lambda1>
							<AreaSection2Name xsi:nil="true" />
							<Lambda2 xsi:nil="true" />
							<AreaSection3Name xsi:nil="true" />
							<Lambda3 xsi:nil="true" />
							<TotalWidth></TotalWidth>
						</AreaSection>
						<PercentageOfSec2 xsi:nil="true" />
						<PercentageOfSec3 xsi:nil="true" />
					</Assembly>
				</Assemblies>
				<SecCalculations>
					<EqThermalConductivitySAS>
						<AirLayerThickness></AirLayerThickness>
						<DirectionOfHeatFlow></DirectionOfHeatFlow>
					</EqThermalConductivitySAS>
				</SecCalculations>
				<WedgeShapedLayers>
					<WedgeAssembly>
						<AssemblyNr></AssemblyNr>
						<AssemblyName></AssemblyName>
						<InteriorRsi></InteriorRsi>
						<ExteriorRse></ExteriorRse>
						<AreaSection>
							<AreaSection1Name></AreaSection1Name>
							<Lambda1></Lambda1>
							<Lambda2 xsi:nil="true" />
							<Lambda3 xsi:nil="true" />
							<TotalWidth></TotalWidth>
						</AreaSection>
						<PercentageOfSec2 xsi:nil="true" />
						<PercentageOfSec3 xsi:nil="true" />
						<WedgeShapedAssemblyLayer>
							<AreaSection1Name></AreaSection1Name>
							<Lambda1></Lambda1>
							<Lambda2 xsi:nil="true" />
							<Lambda3 xsi:nil="true" />
							<TotalWidth xsi:nil="true" />
							<PercentageOfSec2 xsi:nil="true" />
							<PercentageOfSec3 xsi:nil="true" />
						</WedgeShapedAssemblyLayer>
					</WedgeAssembly>
				</WedgeShapedLayers>
			</UValues>;
		
		private var WindowsXML:XML =
			<Windows>
			</Windows>;
		
		private var WindowXML:XML =
			<Window>
			  <Quantity>1</Quantity>
			  <Description></Description>
			  <DeviationFromNorth></DeviationFromNorth>
			  <AngleOfInclinationFromTheHorizontal>90</AngleOfInclinationFromTheHorizontal>
			  <Width></Width>
			  <Height></Height>
			  <AreaNr>1</AreaNr>
			  <GlazingNr>1</GlazingNr>
			  <FrameNr>1</FrameNr>
			  <InstallationLeft>1</InstallationLeft>
			  <InstallationRight>1</InstallationRight>
			  <InstallationSill>1</InstallationSill>
			  <InstallationHead>1</InstallationHead>
			</Window>;
		
		private var WindowSkyXML:XML =
			<Window>
			  	<Quantity>1</Quantity>
			  	<Description></Description>
			  	<DeviationFromNorth>0</DeviationFromNorth>
			  	<AngleOfInclinationFromTheHorizontal>0</AngleOfInclinationFromTheHorizontal>
			  	<Width></Width>
			  	<Height></Height>
				<UserDetermined />
				<UserSubtraction />
			  	<AreaNr>9</AreaNr>
			  	<GlazingNr>1</GlazingNr>
			  	<FrameNr>1</FrameNr>
			  	<InstallationLeft>1</InstallationLeft>
			  	<InstallationRight>1</InstallationRight>
			  	<InstallationSill>1</InstallationSill>
			  	<InstallationHead>1</InstallationHead>
			</Window>;
		
		private var winTypeTag:XML = 
			<WinType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
				<WindowGlazings>
				</WindowGlazings>
				<WindowFrames>
				</WindowFrames>
			</WinType>;
		
		private var WinTypeXML:XML =
			<WinType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
				<WindowGlazings>
					<WindowGlazing>
						<GlazingName>Kur</GlazingName>
						<gValue></gValue>
						<ugValue></ugValue>
					</WindowGlazing>
				</WindowGlazings>
				<WindowFrames>
					<WindowFrame>
						<FrameName></FrameName>
						<UfValueFrame></UfValueFrame>
						<WidthLeft></WidthLeft>
						<WidthRight></WidthRight>
						<WidthBelow xsi:nil="true" />
						<WidthAbove></WidthAbove>
						<ThermalBridgeYSpacer></ThermalBridgeYSpacer>
						<ThermalBridgeYInstallation></ThermalBridgeYInstallation>
					</WindowFrame>
				</WindowFrames>
			</WinType>;
		
		private var project:Project;
		private var areaController:AreasController;
		private var calculations:Calculations;
		
		private var glazingNumber:Number;
		private var frameNumber:Number;
		
		public function PhppXMLexport()
		{
			this.project = FlexGlobals.topLevelApplication.project;
			this.areaController = new AreasController();
			this.calculations = FlexGlobals.topLevelApplication.calculations;
		}
		
		public function testExport():XML
		{
			addVerificationData();
			
			addAreasAndElementsTags();
			
			addThreatedFloorArea();
			
			addDoors();
			
			addBuildingElements();
			
			addThermalBridges();
			
			addWindows();
			
			return exportXML;
		}
		
		//appends Areas and BuildingElements tags
		private function addAreasAndElementsTags():void
		{
			exportXML.appendChild(AreasXML);
			AreasXML.appendChild(buildingElementsTag);
		}
		
		//appends the Verification Data
		private function addVerificationData():void
		{
			VerificationXML.Building.Name = project.projectInfo.object.name;
			VerificationXML.Building.LocationAndClimate = project.projectInfo.object.address.street + " " + project.projectInfo.climateZone.label;
			VerificationXML.Building.PostCodeCity = project.projectInfo.object.address.town;
			VerificationXML.Building.Country = project.projectInfo.object.address.country;
			
			VerificationXML.Architect.Name = project.projectInfo.architect.name;
			VerificationXML.Architect.Street = project.projectInfo.architect.address.street;
			VerificationXML.Architect.PostCodeCity = project.projectInfo.architect.address.town;
			VerificationXML.Architect.Country = project.projectInfo.architect.address.country;
			
			VerificationXML.MechanicalSystem.Name = project.projectInfo.builder.name;
			VerificationXML.MechanicalSystem.Street = project.projectInfo.builder.address.street;
			VerificationXML.MechanicalSystem.PostCodeCity = project.projectInfo.builder.address.town;
			VerificationXML.MechanicalSystem.Country = project.projectInfo.builder.address.country;
			
			VerificationXML.InteriorTemperature = project.projectInfo.interiorTemperature;
			VerificationXML.CalcElecBuildType = project.projectInfo.buildingType;
			VerificationXML.PlannedNoOcupantsType = project.projectInfo.usage;
			
			exportXML.appendChild(VerificationXML);
		}
		
		//append total heated space area
		private function addThreatedFloorArea():void
		{
			threatedFloorArea.UserDetermined = project.areas.totalHeatedSpaceArea;
			buildingElementsTag.appendChild(threatedFloorArea);
		}
		
		//appends all solid components to the XML
		private function addBuildingElements():void
		{
			var resourceManager:IResourceManager = ResourceManager.getInstance();
			
			for each (var solidComps:SolidComponent in areaController.getAllSolidComponentsWithAttachedConstruction()) 
			{	
				var groupNum:Number;
				
				if(solidComps.description == resourceManager.getString('systemtexts','exteriorWallToAmbientAir'))
				{
					groupNum = 8;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','exteriorWallToGround'))
				{
					groupNum = 9;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','externalWallToCellar'))
				{
					groupNum = 12;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','externalWallPartitionWall'))
				{
					groupNum = 18;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','roofAreaSloped'))
				{
					groupNum = 10;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','roofAreaFlat'))
				{
					groupNum = 10;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','groundSlab'))
				{
					groupNum = 11;
				}
				else if(solidComps.description == resourceManager.getString('systemtexts','groundSlabAgainstCellar'))
				{
					groupNum = 13;
				}
				
				buildingElement = <BuildingElement>
					<Description>{solidComps.description}</Description>
					<GroupNr>{groupNum}</GroupNr>
					<Quantity>{solidComps.quantity}</Quantity>
					<A>{solidComps.length}</A>
					<B>{solidComps.height}</B>
					<UserDetermined>{solidComps.quantity * solidComps.length * solidComps.height}</UserDetermined>
					<UserSubtraction>{solidComps.quantity * solidComps.length * solidComps.height}</UserSubtraction>
					<Nr>1</Nr>
				</BuildingElement>;
				
				buildingElementsTag.appendChild(buildingElement);
			}
		}
		
		//appends thermal bridges length
		private function addThermalBridges():void
		{
			thermalBridges.ThermalBridge.UserDeterminedLength = calculations.lengthOfThermalBridges;
			buildingElementsTag.appendChild(thermalBridges);
		}
		
		//no information inside at the moment
		private function addRadiation():void
		{
			buildingElementsTag.appendChild(radiation);
		}
		
		//appends all doors
		private function addDoors():void
		{
			var length:Number = 0;
			var height:Number = 0;
			var area:Number = 0;
			
			for each(var door:TransparentComponent in areaController.getDoorsWithAttachedConstruction())
			{
				length += door.length;
				height += door.height;
				area += door.area;
			}
			
			doorElement = <ExteriorDoor>
							<A></A>
							<B></B>
							<UserDetermined>{area.toFixed(2)}</UserDetermined>
							<UserSubtraction></UserSubtraction>
							<UValueWm2K/>
							<Quantity>1</Quantity>
						</ExteriorDoor>;
			
			buildingElementsTag.appendChild(doorElement);
		}
		
		//appends all windows
		private function addWindows():void
		{
			exportXML.appendChild(WindowsXML);
			exportXML.appendChild(winTypeTag);
			
			var glazingNum:Number;
			var frameNum:Number;
			
			for each(var window:TransparentComponent in areaController.getWindowsWithAttachedConstruction())
			{			
				if(glazingExists(window.construction.gValue, window.construction.uValue))
				{
					glazingNum = glazingNumber;
				}
				else
				{
					glazingElement = <WindowGlazing>
								        <GlazingName>{window.construction.glazingName}</GlazingName>
								        <gValue>{window.construction.gValue}</gValue>
								     	<ugValue>{window.construction.uValue}</ugValue>
								     </WindowGlazing>;
					
					exportXML.WinType.WindowGlazings.appendChild(glazingElement);
					
					glazingNum = exportXML.WinType.WindowGlazings.children().length();
				}
				
				if(frameExists(window.construction.ufValue))
				{
					frameNum = frameNumber;
				}
				else
				{
					frameElement = <WindowFrame>
										<FrameName>{window.construction.frameName}</FrameName>
										<UfValueFrame>{window.construction.ufValue}</UfValueFrame>
										<WidthLeft/>
										<WidthRight/>
										<WidthBelow/>
										<WidthAbove/>
										<ThermalBridgeYSpacer/>
										<ThermalBridgeYInstallation/>
									 </WindowFrame>;
					
					exportXML.WinType.WindowFrames.appendChild(frameElement);
					
					frameNum = exportXML.WinType.WindowFrames.children().length();
				}
				
				var complexSolidComp:ComplexSolidComponent = areaController.getComplexSolidComponentById(window.parentComponent);
				
				var arrc:ArrayCollection = areaController.getAllSolidComponentsWithAttachedConstruction();
				var num:Number = arrc.getItemIndex(complexSolidComp) + 1;
				
				windowElement = <Window>
								<Quantity>{window.quantity}</Quantity>
								<Description>{window.description}</Description>
								<DeviationFromNorth>{complexSolidComp.orientation}</DeviationFromNorth>
								<AngleOfInclinationFromTheHorizontal>90</AngleOfInclinationFromTheHorizontal>
								<Width>{window.length}</Width>
								<Height>{window.height}</Height>
								<AreaNr>{num}</AreaNr>
								<GlazingNr>{glazingNum}</GlazingNr>
								<FrameNr>{frameNum}</FrameNr>
								<InstallationLeft>1</InstallationLeft>
								<InstallationRight>1</InstallationRight>
								<InstallationSill>1</InstallationSill>
								<InstallationHead>1</InstallationHead>
							</Window>;
				
				WindowsXML.appendChild(windowElement);
			}
		}
		
		private function glazingExists(gValue:Number, ugValue:Number):Boolean
		{
			var result:Boolean = false;
			glazingNumber = 0;
			
			for each(var xml:XML in exportXML.WinType.WindowGlazings.WindowGlazing)
			{
				glazingNumber++;
				
				if(xml.gValue == gValue && xml.ugValue == ugValue)
				{
					result = true;
				}
			}
			
			return result;
		}
		
		private function frameExists(ufValue:Number):Boolean
		{
			var result:Boolean = false;
			frameNumber = 0;
			
			for each(var xml:XML in exportXML.WinType.WindowFrames.WindowFrame)
			{
				frameNumber++;
				
				if(xml.UfValueFrame == ufValue)
				{
					result = true;
				}
			}
			
			return result;
		}
		
		public function getXMLexport(projectXML:XML, overviewXML:XML, detailXML:XML, namesObj:Object):XML
		{
			var northAgr:Number = 0;
			var eastAgr:Number = 0;
			var southAgr:Number = 0;
			var westAgr:Number = 0;
			var northA:Number = 0;
			var eastA:Number = 0;
			var southA:Number = 0;
			var westA:Number = 0;
			var doorH:Number = 0;
			var doorW:Number = 0;
			var doorA:Number = 0;
			var roofA:Number = 0;
			
			VerificationXML.Building.Name = checkElement(projectXML.ProjectdataArea.Object);
			VerificationXML.Building.LocationAndClimate = checkElement(projectXML.ProjectdataArea.Street);
			VerificationXML.Building.PostCodeCity = checkElement(projectXML.ProjectdataArea.ZIP) + checkElement(projectXML.ProjectdataArea.Town);
			VerificationXML.Building.Country = checkElement(FlexGlobals.topLevelApplication.projectData.landObjectInput.selectedLabel);
			VerificationXML.Architect.Name = checkElement(projectXML.ProjectdataArea.Architect);
			VerificationXML.Architect.Street = checkElement(projectXML.ProjectdataArea.ArchitectStreet);
			VerificationXML.Architect.PostCodeCity = checkElement(projectXML.ProjectdataArea.ArchitectZIP) + checkElement(projectXML.ProjectdataArea.ArchitectTown);
			VerificationXML.Architect.Country = checkElement(FlexGlobals.topLevelApplication.projectData.landArchitectInput.selectedLabel);
			VerificationXML.MechanicalSystem.Name = checkElement(projectXML.ProjectdataArea.Builder);
			VerificationXML.MechanicalSystem.Street = checkElement(projectXML.ProjectdataArea.BuilderStreet);
			VerificationXML.MechanicalSystem.PostCodeCity = checkElement(projectXML.ProjectdataArea.BuilderZIP) + checkElement(projectXML.ProjectdataArea.BuilderTown);
			VerificationXML.MechanicalSystem.Country = checkElement(FlexGlobals.topLevelApplication.projectData.landBuilderInput.selectedLabel);
			VerificationXML.YearOfConstruction = checkElement(projectXML.ObjectdataArea.YearOfConstruction);
			VerificationXML.InteriorTemperature = checkElement(projectXML.UsagedataArea.InteriorTemperature);
			VerificationXML.CalcElecBuildType = checkElement(FlexGlobals.topLevelApplication.projectData.typeofbuildingInput.selectedLabel);
			VerificationXML.PlannedNoOcupants = checkElement(projectXML.UsagedataArea.NumberWE);
			VerificationXML.PlannedNoOcupantsType = checkElement(FlexGlobals.topLevelApplication.projectData.usageInput.selectedLabel);
			for(var i:uint=1 ; i<=20 ; i++)
			{
				if(String(overviewXML.OpaqueComponentsArea['Purpose_'+i]).toLowerCase().indexOf(namesObj.doors.toLowerCase()) >= 0 )
				{
					doorW += Number(checkElement(overviewXML.OpaqueComponentsArea['A_'+i]));
					doorA += Number(checkElement(overviewXML.OpaqueComponentsArea['NetArea_'+i]));
				}
				else if(String(overviewXML.OpaqueComponentsArea['Purpose_'+i]).toLowerCase().indexOf(namesObj.roof.toLowerCase()) >= 0)
				{
					roofA += Number(checkElement(detailXML.OpaqueComponentsArea.Component[i-1].C_Area));
				}
			}
			AreasXML..ExteriorDoor.A = doorW;
			AreasXML..ExteriorDoor.B = Math.round(100*doorA/doorW)/100;
			AreasXML..ExteriorDoor.UserDetermined = doorA;
			AreasXML..ExteriorDoor.UserSubtraction = doorA;
			for each (var item:XML in detailXML.OpaqueComponentsArea.Component) 
			{ 
				if(item.ComponentName.toLowerCase().indexOf(namesObj.wallsGr.toLowerCase()) >= 0)
				{
					northAgr += Number(item.C_North);
					eastAgr += Number(item.C_East);
					southAgr += Number(item.C_South);
					westAgr += Number(item.C_West);
				}
				else if(item.ComponentName.toLowerCase().indexOf(namesObj.wallsAir.toLowerCase()) >= 0)
				{
					northA += Number(item.C_North);
					eastA += Number(item.C_East);
					southA += Number(item.C_South);
					westA += Number(item.C_West);
				}
				/*else if(item.ComponentName.toLowerCase().indexOf(namesObj.doors.toLowerCase()) >= 0)
				{
					northA += Number(item.C_North);
					eastA += Number(item.C_East);
					southA += Number(item.C_South);
					westA += Number(item.C_West);
				}*/
			}
			northAgr = roundVal(northAgr);
			eastAgr = roundVal(eastAgr);
			southAgr = roundVal(southAgr);
			westAgr = roundVal(westAgr);
			northA = roundVal(northA);
			eastA = roundVal(eastA);
			southA = roundVal(southA);
			westA = roundVal(westA);
			doorH = roundVal(doorH);
			doorW = roundVal(doorW);
			doorA = roundVal(doorA);
			roofA = roundVal(roofA);
			
			for each (var propw:XML in AreasXML.BuildingElements.BuildingElement) 
			{ 
				if(propw.Description == 'Exterior wall against ground north')
				{
					propw.Description = namesObj.wallsGr+' '+String(namesObj.north).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.northWgr);
					propw.B = Math.round(100*northAgr/Number(FlexGlobals.topLevelApplication.xmlData.metadata.northWgr))/100;
					propw.UserDetermined = northAgr;
					propw.UserSubtraction = northAgr;
				}
				else if(propw.Description == 'Exterior wall against ground east')
				{
					propw.Description = namesObj.wallsGr+' '+String(namesObj.east).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.eastWgr);
					propw.B = Math.round(100*eastAgr/Number(FlexGlobals.topLevelApplication.xmlData.metadata.eastWgr))/100;
					propw.UserDetermined = eastAgr;
					propw.UserSubtraction = eastAgr;
				}
				else if(propw.Description == 'Exterior wall against ground south')
				{
					propw.Description = namesObj.wallsGr+' '+String(namesObj.south).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.southWgr);
					propw.B = Math.round(100*southAgr/Number(FlexGlobals.topLevelApplication.xmlData.metadata.southWgr))/100;
					propw.UserDetermined = southAgr;
					propw.UserSubtraction = southAgr;
				}
				else if(propw.Description == 'Exterior wall against ground west')
				{
					propw.Description = namesObj.wallsGr+' '+String(namesObj.west).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.westWgr);
					propw.B = Math.round(100*westAgr/Number(FlexGlobals.topLevelApplication.xmlData.metadata.westWgr))/100;
					propw.UserDetermined = westAgr;
					propw.UserSubtraction = westAgr;
				}
				else if(propw.Description == 'Exterior wall against air north')
				{
					propw.Description = namesObj.wallsAir+' '+String(namesObj.north).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.northW);
					propw.B = Math.round(100*northA/Number(FlexGlobals.topLevelApplication.xmlData.metadata.northW))/100;
					propw.UserDetermined = northA;
					propw.UserSubtraction = northA;
				}
				else if(propw.Description == 'Exterior wall against air east')
				{
					propw.Description = namesObj.wallsAir+' '+String(namesObj.east).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.eastW);
					propw.B = Math.round(100*eastA/Number(FlexGlobals.topLevelApplication.xmlData.metadata.eastW))/100;
					propw.UserDetermined = eastA;
					propw.UserSubtraction = eastA;
				}
				else if(propw.Description == 'Exterior wall against air south')
				{
					propw.Description = namesObj.wallsAir+' '+String(namesObj.south).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.southW);
					propw.B = Math.round(100*southA/Number(FlexGlobals.topLevelApplication.xmlData.metadata.southW))/100;
					propw.UserDetermined = southA;
					propw.UserSubtraction = southA;
				}
				else if(propw.Description == 'Exterior wall against air west')
				{
					propw.Description = namesObj.wallsAir+' '+String(namesObj.west).slice(0,-1);
					propw.A = Number(FlexGlobals.topLevelApplication.xmlData.metadata.westW);
					propw.B = Math.round(100*westA/Number(FlexGlobals.topLevelApplication.xmlData.metadata.westW))/100;
					propw.UserDetermined = westA;
					propw.UserSubtraction = westA;
				}
				else if(propw.Description == 'Floor Slab')
				{
					propw.Description = namesObj.floor;
					propw.UserDetermined = Number(FlexGlobals.topLevelApplication.xmlData.metadata.floorArea);
					//propw.UserSubtraction = Number(FlexGlobals.topLevelApplication.xmlData.metadata.floorArea);
				}
				else if(propw.Description == 'Roof')
				{
					propw.Description = namesObj.roof;
					propw.UserDetermined = roofA;
					//propw.UserSubtraction = roofA;
				}
			}
			for each (var prop:XML in detailXML.TransparentComponentsArea.Component) 
			{ 
				if(prop.ComponentName.toLowerCase().indexOf(namesObj.skywindows.toLowerCase()) >= 0)
				{
					if(prop.C_Area > 0)
					{
						var winSky:XML = WindowSkyXML.copy();
						winSky.Description = namesObj.skywindows;
						winSky.Width = Number(prop.C_Area);
						winSky.Height = 1;
						//winSky.UserDetermined = Number(prop.C_Area);
						//winSky.UserSubtraction = Number(prop.C_Area);
						WindowsXML.appendChild(winSky);
					}
				}
				else if(prop.ComponentName.toLowerCase().indexOf(namesObj.windows.toLowerCase()) >= 0)
				{
					var w:String;
					var h:String;
					var air:Number = (Number(prop.ComponentFloor)>=0)?4:0;
					if(prop.C_North > 0)
					{
						w = prop.A_North;
						h = prop.B_North;
						var winN:XML = WindowXML.copy();
						winN.Description = String(namesObj.north).slice(0,-1)+' '+prop.ComponentName;
						winN.DeviationFromNorth = 0;
						winN.Width = w;
						winN.Height = h;
						winN.AreaNr = air+1;
						WindowsXML.appendChild(winN);
					}
					if(prop.C_East > 0)
					{
						w = prop.A_East;
						h = prop.B_East;
						var winE:XML = WindowXML.copy();
						winE.Description = String(namesObj.east).slice(0,-1)+' '+prop.ComponentName;
						winE.DeviationFromNorth = 90;
						winE.Width = w;
						winE.Height = h;
						winE.AreaNr = air+2;
						WindowsXML.appendChild(winE);
					}
					if(prop.C_South > 0)
					{
						w = prop.A_South;
						h = prop.B_South;
						var winS:XML = WindowXML.copy();
						winS.Description = String(namesObj.south).slice(0,-1)+' '+prop.ComponentName;
						winS.DeviationFromNorth = 180;
						winS.Width = w;
						winS.Height = h;
						winS.AreaNr = air+3;
						WindowsXML.appendChild(winS);
					}
					if(prop.C_West > 0)
					{
						w = prop.A_West;
						h = prop.B_West;
						var winW:XML = WindowXML.copy();
						winW.Description = String(namesObj.west).slice(0,-1)+' '+prop.ComponentName;
						winW.DeviationFromNorth = 270;
						winW.Width = w;
						winW.Height = h;
						winW.AreaNr = air+4;
						WindowsXML.appendChild(winW);
					}
				}
			}
			
			exportXML.appendChild(VerificationXML);
			exportXML.appendChild(AreasXML);
			exportXML.appendChild(UValuesXML);
			exportXML.appendChild(WindowsXML);
			exportXML.appendChild(WinTypeXML);
			
			return exportXML;
		}
		private function checkElement(element:String):String
		{
			if(element != '' && element != '-Please select-' && element != '-Bitte wählen-')
			{
				return element
			}
			else
			{
				return '';
			}
		}
		protected function roundVal(val:Number):Number
		{
			var coef:uint = 100;
			val = Math.round(val*coef)/coef;
			return val
		}
	}
}